package com.archeocs.figone.lib;

//Author:
//Miłosz Pigłas, Archeocs milosz@archeocs.com
//
//Copyright (c) 2010, Miłosz Pigłas, Archeocs
//
//All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//
//* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the distribution.
//* Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
//A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * Reprezentuje pojedynczy obrazek, ktory ma znalezc sie na tworzonej tablicy
 * @author Milosz Piglas
 *
 */
public class Rycina {
	
	private BufferedImage ryc;
	public double rsz, rwy;
    private int ileSz, ileWy;
    private int kwKra;
    private String nazwa;
	private String opis = null;
    
	/**
	 * Konstruktor obiektu
	 * @param sciezka sciezka do pliku obrazka
	 */
    public Rycina (String sciezka)
    {
    	try {
    		nazwa = sciezka;
			ryc = ImageIO.read(new File(sciezka));
			rsz = K.itod(ryc.getWidth());
			rwy = K.itod(ryc.getHeight());
			kwKra = Macierz.KRAW_DL;
			ileSz = K.dtoi(Math.ceil(rsz / kwKra));
			ileWy = K.dtoi(Math.ceil(rwy / kwKra));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    }
    
    /**
     * Zwraca obrazek reprezentowany przez instancje klasy
     * @return
     */
    public BufferedImage getObrazek()
    {
    	return ryc;
    }
    
    /**
     * Zwraca obrazek reprezentowany przez instancje klasy w podanej skali
     * @param skala
     * @return
     */
    public Image getObrazek(double skala)
    {
    	int w = K.dtoi(rsz * skala);
    	int h = K.dtoi(rwy * skala);
    	Image skImg = ryc.getScaledInstance(w, h, Image.SCALE_DEFAULT);
    	return skImg;
    }
    
    /**
     * Ile "kwadratow" o krawedzi 20 px zajmuje obrazek
     * @return
     */
    public int getSz()
    {
    	return ileSz;
    }
    
    /**
     * Ile "kwadratow" o krawedzi 20 px zajmuje obrazek
     * @return
     */
    public int getWy()
    {
    	return ileWy;
    }
    
    /**
     * Pole obrazka w pikselach
     * @return
     */
    public int getPole()
    {
    	return ryc.getWidth() * ryc.getHeight();
    }
    
    /**
     * Sciezka do pliku
     * @return
     */
    public String getNazwa()
    {
    	return nazwa;
    }

    /**
     * Ustawia opis obrazka
     * @param opis
     */
	public void setOpis(String opis) {
		// TODO Auto-generated method stub
		this.opis = opis;
		
	}
	
	/**
	 * Pobiera opis obrazka
	 * @return
	 */
	public String getOpis()
	{
		return opis;
	}
    
    

}
